using System;
using System.Collections.Specialized;
using System.Net;

namespace Subtext.Akismet
{
    public class Comment : IComment
    {
        private readonly IPAddress ipAddress;
        private readonly NameValueCollection serverEnvironmentVariables = new NameValueCollection();
        private readonly string userAgent;
        private string author;
        private string authorEmail;
        private Uri authorUrl;
        private string commentType;
        private string content;
        private Uri permalink;
        private string referer;

        /// <summary>
        /// Initializes a new instance of the <see cref="Comment"/> class.
        /// </summary>
        /// <param name="authorIpAddress">The author ip address.</param>
        /// <param name="authorUserAgent">The author user agent.</param>
        public Comment(IPAddress authorIpAddress, string authorUserAgent)
        {
            ipAddress = authorIpAddress;
            userAgent = authorUserAgent;
        }

        #region IComment Members

        /// <summary>
        /// The name submitted with the comment.
        /// </summary>
        public string Author
        {
            get { return author; }
            set { author = value; }
        }

        /// <summary>
        /// The email submitted with the comment.
        /// </summary>
        public string AuthorEmail
        {
            get { return authorEmail; }
            set { authorEmail = value; }
        }

        /// <summary>
        /// The url submitted if provided.
        /// </summary>
        public Uri AuthorUrl
        {
            get { return authorUrl; }
            set { authorUrl = value; }
        }

        /// <summary>
        /// Content of the comment
        /// </summary>
        public string Content
        {
            get { return content; }
            set { content = value; }
        }

        /// <summary>
        /// The HTTP_REFERER header value of the 
        /// originating comment.
        /// </summary>
        public string Referer
        {
            get { return referer; }
            set { referer = value; }
        }

        /// <summary>
        /// Permanent location of the entry the comment was 
        /// submitted to.
        /// </summary>
        public Uri Permalink
        {
            get { return permalink; }
            set { permalink = value; }
        }

        /// <summary>
        /// User agent of the requester. (Required)
        /// </summary>
        public string UserAgent
        {
            get { return userAgent; }
        }

        /// <summary>
        /// May be one of the following: {blank}, "comment", "trackback", "pingback", or a made-up value 
        /// like "registration".
        /// </summary>
        public string CommentType
        {
            get { return commentType; }
            set { commentType = value; }
        }

        /// <summary>
        /// IPAddress of the submitter
        /// </summary>
        public IPAddress IpAddress
        {
            get { return ipAddress; }
        }

        /// <summary>
        /// Optional collection of various server environment variables. 
        /// </summary>
        public NameValueCollection ServerEnvironmentVariables
        {
            get { return serverEnvironmentVariables; }
        }

        #endregion
    }
}